﻿using Dt261.Base;
using SQLite;
using SQLiteNetExtensions.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dt261.Model
{
    [Table("ResultDataSet")]
    public class ResultDataSet
    {

        public ResultDataSet()
        {
            Entrys = new List<ResultEntry>();
        }
        private int headsetMode;
        private int id;
        private int isLine;
        private int isRight;
        private int painStrokeWidth;
        private int paintColor;
        private int pointRadius;
        private string uid;
        //@property(nullable, nonatomic, retain) NSSet<ResultEntry*>* entryList;
        //@property(nullable, nonatomic, retain) PureToneResult* result;

        private string resultId;//PureToneResult

        [PrimaryKey, AutoIncrement]
        public int Id { get => id; set => id = value; }
        public string Uid { get => uid; set => uid = value; }

        public int HeadsetMode { get => headsetMode; set => headsetMode = value; }

        public int IsLine { get => isLine; set => isLine = value; }
        public int IsRight { get => isRight; set => isRight = value; }
        public int PainStrokeWidth { get => painStrokeWidth; set => painStrokeWidth = value; }
        public int PaintColor { get => paintColor; set => paintColor = value; }
        public int PointRadius { get => pointRadius; set => pointRadius = value; }
        public string ResultId { get => resultId; set => resultId = value; }

  
        [OneToMany]
        public List<ResultEntry> Entrys { get ; set; }

        public Dictionary<string, Object> getResultDictory()
        {
            //            //    public AudiometerTestBasics testBasicsId;    //测试基础编号ID
            //            //    public long hz125;
            //            //    public long hz250;
            //            //    public long hz500;
            //            //    public long hz750;
            //            //    public long hz1000;
            //            //    public long hz1500;
            //            //    public long hz2000;
            //            //    public long hz3000;
            //            //    public long hz4000;
            //            //    public long hz6000;
            //            //    public long hz8000;
            //            //    public int isRight;          //左右耳   0左耳   1右耳
            //            //    public int isHeadsetMode;    //气骨导   0气导   1骨导
            //            //    public int isConnection;     //是否连线 0不连   1连

            //            NSMutableDictionary* retDict = [NSMutableDictionary dictionaryWithCapacity: 10];

            Dictionary<string, Object> retDict = new Dictionary<string, Object>();
            //    [retDict addEntriesFromDictionary:@{@"isRight":self.isRight,@"isHeadsetMode":@0,@"isConnection":@1}];
            retDict.Add("isRight", IsRight == 1 ? 1 : 0);
            retDict.Add("isHeadsetMode", 0);
            retDict.Add("isConnection", 1);

            retDict.Add("hz125", -1);
            retDict.Add("hz250", -1);
            retDict.Add("hz500", -1);
            retDict.Add("hz750", -1);
            retDict.Add("hz1000", -1);
            retDict.Add("hz1500", -1);
            retDict.Add("hz2000", -1);
            retDict.Add("hz3000", -1);
            retDict.Add("hz4000", -1);
            retDict.Add("hz6000", -1);
            retDict.Add("hz8000", -1);
            foreach (ResultEntry entry in Entrys)
            {
                string key = "hz" + entry.ValueX;
                ResultCommand command = new ResultCommand(entry.ValueY, entry.PointState == 1, entry.PointType, entry.IsUserResp == 1, entry.TestToneType,
                    entry.TestToneTime, entry.MarkType, entry.YanbiType
                    );

                long value = command.getRecord();

                retDict[key] =  value;


            }

            //     [retDict addEntriesFromDictionary:@{@"hz125":@(-1),@"hz250":@(-1),@"hz500":@(-1),@"hz750":@(-1),@"hz1000":@(-1),@"hz1500":@(-1),@"hz2000":@(-1),@"hz3000":@(-1),@"hz4000":@(-1),@"hz6000":@(-1),@"hz8000":@(-1)}];

            //    for(ResultEntry* entry in [self.entryList allObjects])
            //    {
            ////        NSDictionary* valueDict = @{@"hz":entry.valueX,@"db":entry.valueY,@"maskV":entry.pointType,@"mask":entry.pointState};

            //        NSString* key = [NSString stringWithFormat: @"hz%@", entry.valueX];

            //ResultCommand* command = [ResultCommand new];

            //command.db = [entry.valueY intValue];
            //        command.isYanbi = [entry.pointState boolValue];
            //        command.yanbiDB = [entry.pointType intValue];
            //        command.isUserResp = [entry.isUserResp boolValue] ;
            //        command.testToneType = [entry.testToneType intValue];
            //        command.testToneTime = [entry.testToneTime intValue];
            //        command.markType = [entry.markType intValue];
            //        command.yanbiType = [entry.yanbiType intValue];
            //        NSNumber* value =@([command getRecord]);

            //        [retDict setValue:value forKey:key];
            //    }
            return retDict;
            //        }



        }
    }
}
